package 设计模式.代理模式.静态代理;

import java.util.Random;

public class Tank  implements Movable {


    @Override
    public void move() {
        //坦克移动
        System.out.println("tank moving....");
        try {
            Thread.sleep(new Random().nextInt(5000));
            //随机产生1-5秒，模拟坦克在移动
        }catch (InterruptedException e)
        {
            e.printStackTrace();
        }
    }
}
class TankTimeProxy implements Movable{
    private Movable tank;

    public TankTimeProxy(Movable tank) {
        this.tank = tank;
    }

    @Override
    public void move() {
        //在前面做一些事情，记录开始时间
        long time_start = System.currentTimeMillis();
        System.out.println("start time:" +time_start);
        tank.move();

        //在后面做一些事情；记录结束时间，并计算move（）运行时间
        long time_end = System.currentTimeMillis();

        System.out.println("end time: "+time_end);
        System.out.println("spend all time:"+(time_end-time_start)/1000+"s");
    }
}

class TankLogProxy implements Movable{
    private Movable tank;

    public TankLogProxy(Movable tank) {
        this.tank = tank;
    }

    @Override
    public void move() {
        //移动前记录日志
        System.out.println("tank log start...");

        tank.move();
        //移动后记录日志
        System.out.println("tank log end...");

    }
}